package demo;


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.ListIterator;

//双向 不带头 非循环
public class Test {
    public static void main(String[] args) {

        //1. 第一种构造方法
        LinkedList<String> linkedList = new LinkedList<>();
//2. 第二种构造方法
        ArrayList<String> list = new ArrayList<>();
        LinkedList<String> linkedList2 = new LinkedList<>(list);


        linkedList.add("hello");
        linkedList.add("abc");
        linkedList.add("def");
        linkedList.add("ghi");
        //1. 第一种打印
        System.out.println(linkedList);

        //2. foreach
        for (String x: linkedList) {
            System.out.print(x+" ");
        }
        System.out.println();
        //3. for
        for (int i = 0; i < linkedList.size(); i++) {
            System.out.print(linkedList.get(i) +" ");
        }
        System.out.println();
        //4.迭代器
        ListIterator<String> it = linkedList.listIterator();
        while(it.hasNext()){
            System.out.print(it.next() + " ");
        }
        System.out.println();
        //5. 反向遍历
        ListIterator<String> it2 = linkedList.listIterator(linkedList.size());
        while(it2.hasPrevious()){
            System.out.print(it2.previous() + " ");
        }

/*        [hello, abc, def, ghi]
        hello abc def ghi
        hello abc def ghi
        hello abc def ghi
        ghi def abc hello*/


    }
    public static void main1(String[] args) {
        MyLinkedList myLinkedList = new MyLinkedList();
        myLinkedList.addFirst(1);
        myLinkedList.addFirst(2);
        myLinkedList.addFirst(3);
        myLinkedList.addFirst(4);
        myLinkedList.addFirst(5);
        myLinkedList.addFirst(5);
        myLinkedList.addFirst(5);


        myLinkedList.display();
        myLinkedList.addIndex(3,99);

        myLinkedList.display();

        LinkedList<Integer> linkedList = new LinkedList<>();
        myLinkedList.remove(5);
        myLinkedList.display();
        myLinkedList.removeAllKey(5);
        myLinkedList.display();
    }
}
